//
//  BindingDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/27.
//

import SwiftUI

struct BindingDemo: View {
    
    @State var backgroundColor: Color = .green
    @State var title: String = "This is the title"
    
    var body: some View {
        
        ZStack {
            backgroundColor
                .ignoresSafeArea(.all)
            
            VStack {
                Text(title)
                    .foregroundColor(.white)
                ButtonView(backgroundColor: $backgroundColor, title: $title)
            }

        }
    }
}

struct ButtonView: View {
    
    @Binding var backgroundColor: Color
    
    @State var buttonColor: Color = .blue
    
    @Binding var title: String
    
    var body: some View {
        Button {
            backgroundColor = Color.orange
            buttonColor = .pink
            title = "New title"
        } label: {
            Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
                .foregroundColor(.white)
                .padding()
                .background(buttonColor)
                .cornerRadius(10)
        }
    }
}

#Preview {
    BindingDemo()
}
